package com.cnd.scm.orm;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 从Spring容器中获取bean
 */
@Component
public class SpringBeanUtils implements ApplicationContextAware {

    private static ApplicationContext act;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.act = applicationContext;
    }

    public static final<T> T getBean(Class<T> T) {
        return act.getBean(T);
    }

    public static Object getBean(String beanName) {
        return act.getBean(beanName);
    }
}
